package com.iaiai.cobra.platform.baidu;

import com.iaiai.cobra.common.util.JsonUtil;
import com.iaiai.cobra.common.util.web.HttpsUtil;
import com.iaiai.cobra.platform.baidu.bean.BaiduQueryIpv4AddressResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.hc.core5.http.ParseException;

import java.io.IOException;
import java.net.URISyntaxException;

/**
 * Created with AliyunIpAddress.
 * Package: com.iaiai.cobra.platform.ali
 * Author: iaiai
 * Create Time: 2024/7/29 21:47
 * QQ: 176291935
 * Email: 176291935@qq.com
 * Description: IP归属地查询API
 */
@Slf4j
public class BaiduIpAddress {

    //查询当前ip地址
    public static BaiduQueryIpv4AddressResponse queryIpv4Address() throws IOException, URISyntaxException, ParseException {
        String response = new HttpsUtil.Builder().build().get("https://qifu-api.baidubce.com/ip/local/geo/v1/district");
        log.info("百度 - 查询ip地址：{}",response);
        return JsonUtil.getInstance().deserialize(response, BaiduQueryIpv4AddressResponse.class);
    }

}
